﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CalculateSum
{
    class CalculateSum
    {
        static void Main(string[] args)
        {
            Console.Write("X = ");
            int x = Int32.Parse(Console.ReadLine());
            if (x <= 0)
            {
                Console.WriteLine("X must be greater than 0!");
                return;
            }

            
            Console.Write("N = ");
            int n = Int32.Parse(Console.ReadLine());
            if (n <= 0)
            {
                Console.WriteLine("N must be greater than 0!");
                return;
            }

            decimal sum = 1M; ;
            decimal factorial = 1M;
            decimal xByX = 1M;
            for (int i = 1; i <= n; i++)
            {
                try
                {
                    factorial *= i;
                    xByX *= x;
                    sum += (factorial / xByX);
                }
                catch (OverflowException)
                {
                    Console.WriteLine("The sum is too big!");
                    break;
                }

            }
            Console.WriteLine(sum);
        }
    }
}
